<!--  -->
<template>
  <div>
    <el-dialog title="个人信息" :visible="dialogVisible" width="30%" @close="changeShow">
      <el-form :model="form" size="small" label-width="100px">
        <el-form-item label="科目">
          <el-radio-group v-model="form.mainSub">
            <el-radio label="历史">历史</el-radio>
            <el-radio label="物理">物理</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="分数">
          <el-input v-model="form.num" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="changeShow">取 消</el-button>
        <el-button type="primary" @click="sub">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { updateUser } from '@/api/user/user'
export default {
  props: ['dialogVisible'],
  data() {
    return {
      form: {
        mainSub: '',
        num: ''
      }
    }
  },
  mounted() {
    const user = JSON.parse(localStorage.getItem('user'))
    // console.log(user)
    this.form.mainSub = user.mainSub
    this.form.num = user.num
  },
  methods: {
    changeShow() {
      this.$emit('isShow', false)
    },
    sub() {
      const user = JSON.parse(localStorage.getItem('user'))
      user.mainSub = this.form.mainSub
      user.num = this.form.num
      const param = {
        id: user.id,
        mainSub: this.form.mainSub,
        num: this.form.num
      }
      // console.log(param)
      updateUser(param)
      localStorage.setItem('user', JSON.stringify(user))
      this.$emit('isShow', false)
    }
  }
}
</script>

<style scoped></style>
